//
// Created by 原帅 on 2021/2/13.
//

#include "IETasksInvoker.h"

IETasksInvoker::Builder::Builder() {
    this->invoker = new IETasksInvoker();
    this->builder = this;
}

IETasksInvoker::Builder IETasksInvoker::Builder::addInvokeTask(IETaskInterface *task) {
    if (this->invoker->tasksMap[task->taskID()] == nullptr){
        this->invoker->tasksMap[task->taskID()] = new vector<IETaskInterface*>();
    }
    this->invoker->tasksMap[task->taskID()]->push_back(task);  //todo need duplication check?
    return IETasksInvoker::Builder();
}

IETasksInvoker *IETasksInvoker::Builder::build() {
    return invoker;
}

void IETasksInvoker::runloopTask(void *arg) {
    //todo working hard now
    unsigned long tid = TASK_ID_TASKTEST;
    for (auto task : *this->tasksMap[tid]){
        task->doTask();
    }
}
